﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="searchForm">
                    <div class="select-list">
                        <ul>
                            <li>
                                编号：<input type="text" name="stock_no" id="stock_no" />
                            </li>
                            <li>
                                名称：<input type="text" name="stock_name" id="stock_name" />
                            </li>
                             <li>
                                概念标签：<input type="text" name="stock_tag" id="stock_tag" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" id="searchButton"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" id="resetButton"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add();" data-id="0" data-role="stock:remark:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="edit(this);" data-id="0" data-role="stock:remark:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="removeAll(this);" data-id="0" data-role="stock:remark:delete">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info multiple disabled" onclick="setTop(this)" data-id="0" data-role="cms:content:top">
                    <i class="fa fa-arrow-up"></i> 置顶
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="dataTable"></table>
            </div>
        </div>
    </div>
</div>

@section scripts{

    <script>
        let $table;
        $(function () {

            jutils.handleMessage(function (res) {
                //console.log(res);
                if (res.title === 'cms_content_form') {
                    $table.easyTable('search');
                }

            });
            loadGrid();
        });

        function loadGrid() {
            let options = {
                url: '/stock/stockRemark/GetPageList',
                pageNumber: 1,                      // 初始化加载第一页，默认第一页,并记录
                pageSize:15,                       // 每页的记录行数（*）
                pageList: "10, 25, 50, 100",        // 可供选择的每页的行数（*）
                uniqueId: 'id',
                queryParams: function (params) {
                    let p = {
                        pageNumber: params.pageNumber,
                        pageSize: params.pageSize,
                        stock_no:$('#stock_no').val(),
                        stock_name:$('#stock_name').val(),
                        stock_tag:$('#stock_tag').val()
                    }
                    return p;
                },
                columns: [
                    { field: 'selectItem', checkbox: true },
                    { field: 'stock_no', title: '编号', align: 'left', formatter: renderTitle },
                    { field: 'stock_name', title: '名称', align: 'left', formatter: renderTitle},
                    { field: 'stock_tags', title: '概念标签', align: 'center' },
                    { field: 'update_time', title: '更新日期', align: 'center' },
                    { field: 'create_time', title: '创建日期', align: 'center' }

                    //{
                    //    field: 'id', title: '操作', align: 'center',
                    //    formatter: render
                    //}
                ]

            };
            $table = $('#dataTable').easyTable(options);
        }

        function renderTitle(v, r) {
            var thtml = '<a href="/stock/stockremark/Detail?id='+ r.id + '" target="_blank">' + v + '&nbsp;&nbsp;';
            thtml += '</a>';
            return thtml;

            //return '<a href="/static/content/' + d.channel_id + '/' + d.id + '.html" target="_blank">' + v + '</a>';
        }

        function add() {

            var url = '/stock/StockRemark/Form';
            jutils.openTab('stock_remark_form', '个股资讯', url, { id: 0});
            //jutils.dialogTop("发布文章", url, { id: 0, channelId: channelId }, null, function () {
            //    $table.easyTable('search');
            //});

        }
        function edit() {

            var rows = $table.easyTable("selected");
            if (rows.length == 0) {
                jutils.warn('请选择数据行');
                return;
            }
            var id = rows[0].id;
             var url = '/stock/StockRemark/Form';
            jutils.openTab('stock_remark_form', '个股资讯', url, { id: id });
           
        }

        function removeAll(obj) {
            var rows = $table.easyTable("selected");
            if (rows.length == 0) {
                jutils.warn('请选择数据行');
                return;
            }
            var ids = [];
            for (let i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            jutils.confirm("确认删除选中的文章吗", function () {
                jutils.ajaxGet('/cms/Content/DeleteById', { ids: ids.join() }, function (res) {
                    $table.easyTable('search');
                })
            })
        }


    </script>
}





